package com;

import util.VerifyCodeUtils;

import javax.imageio.ImageIO;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.awt.image.BufferedImage;
import java.io.IOException;


@WebServlet(value = "/VerifyLoginServlet")
public class VerifyLoginServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        //生成验证码和图片
        BufferedImage bufferedImage = VerifyCodeUtils.paintImage(80,20);
        String code = VerifyCodeUtils.getCode();
        //将得到的结果放入session
        request.getSession().setAttribute("code",code.toLowerCase());

        ImageIO.write(bufferedImage,"jpeg",response.getOutputStream());
    }
}
